import 'package:honeypotflutter/modules/billing/model/billing_list.dart';
import 'package:honeypotflutter/modules/billing/model/billing_summation.dart';
import 'package:honeypotflutter/net/public_http.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_modal.dart';
import '../model/billing_param.dart';

class BillingApi {
  /*
  * 获取数量
  * */
  static Future<BillingSummationModel> billingSummation({String? startTime, String? endTime, int? paymentType}) async {
    try {
      Map<String, dynamic> param = {
        "startTime": startTime,
        "endTime": endTime,
        "PaymentType": paymentType ?? 0,
      };
      Map<String, dynamic>? result = await MGHttp.get("api/services/app/PayRecord/GetMyPayRecordSummation", params: param);
      if (result != null) {
        BillingSummationModel model = BillingSummationModel.fromJson(result);
        return model;
      }
      return BillingSummationModel();
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }

  /*
  * 列表
  * */
  static Future<List<BillingListModel>> billingList(BillingParam billingParam) async {
    try {
      Map<String, dynamic> param = billingParam.toJson();
      List? resultList = await MGHttp.get(
        "api/services/app/PayRecord/GetMyAllPayRecord",
        params: param,
      );
      if (resultList != null) {
        List<BillingListModel> list = resultList.map((e) => BillingListModel.fromJson(e)).toList();
        return list;
      }
      return [];
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }
}
